package Plugin_Reprise.editors.my_sql_editor;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;

public class EditorSourceViewerConfiguration extends
		TextSourceViewerConfiguration {
	private ITokenScanner scanner=null;
	private ContentAssistant assistant = null;
	@Override
	public IPresentationReconciler getPresentationReconciler(
			ISourceViewer sourceViewer) {
		PresentationReconciler reconciler=new PresentationReconciler();
		reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
		
		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getScanner());
		reconciler.setDamager(dr,EditorPartitionScannerSQL.SQL_TAG );
		reconciler.setRepairer(dr,EditorPartitionScannerSQL.SQL_TAG );

		
        dr= new DefaultDamagerRepairer(
                new SingleTokenScanner(new TextAttribute(new Color(Display.getCurrent(), EditorScanner.COMMENT), null, SWT.ITALIC)));

        reconciler.setDamager(dr, EditorPartitionScannerSQL.SQL_COMMENT);
        reconciler.setRepairer(dr, EditorPartitionScannerSQL.SQL_COMMENT);

        dr= new DefaultDamagerRepairer(
                new SingleTokenScanner(new TextAttribute(new Color(Display.getCurrent(), EditorScanner.ALIAS), null, SWT.BOLD)));

        reconciler.setDamager(dr, EditorPartitionScannerSQL.SQL_ALIAS);
        reconciler.setRepairer(dr, EditorPartitionScannerSQL.SQL_ALIAS);

        dr= new DefaultDamagerRepairer(
                new SingleTokenScanner(new TextAttribute(new Color(Display.getCurrent(), EditorScanner.TableUV), null, SWT.BOLD)));

        reconciler.setDamager(dr, EditorPartitionScannerSQL.SQL_TableUV);
        reconciler.setRepairer(dr, EditorPartitionScannerSQL.SQL_TableUV);

        
        dr= new DefaultDamagerRepairer(
                new SingleTokenScanner(new TextAttribute(new Color(Display.getCurrent(), EditorScanner.SEPARATOR), null, SWT.BOLD)));

        reconciler.setDamager(dr, EditorPartitionScannerSQL.SQL_SEPARATOR);
        reconciler.setRepairer(dr, EditorPartitionScannerSQL.SQL_SEPARATOR);
		
		return reconciler;
	}

	private ITokenScanner getScanner() {
		if(scanner == null) 
			scanner=new EditorScanner(); 
		return scanner;
	}

	@Override
	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
		if(assistant==null){ 
			assistant = new ContentAssistant(); 
			assistant.setContentAssistProcessor(new EditorContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE); 
			assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); 
			} 
		return assistant; 
	}

	
}
